/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package component;

import processing.core.PApplet;
import processing.core.PImage;

/**
 *
 * @author Caliste
 */
public class LeftTurntable 
{
    private int _x;
    private int _y;
    private int _hw;
    private int _hh;
    private PApplet _app;
    private PImage _img;
    private boolean _isPlayed;
   
    public LeftTurntable(int x, int y, int hw, int hh, PApplet mainApp)
    {
        _x = x;
        _y = y;
        _hw = hw;
        _hh = hh;
        _app = mainApp;
        _img = mainApp.loadImage("C:\\Users\\Caliste\\Pictures\\platine_reloop.gif");
        //_img = mainApp.loadImage("/home/biron/Desktop/platine_reloop.gif");
        _img.resize(200, 200);
    }
    
   public void draw()
   {
       if(_isPlayed)
       {
           //_app.fill(255, 0, 0);
           //_app.rect(_x, _y, _hw, _hh);
           //_app.ellipse(_x, _y, _hw, _hh);

           _app.pushMatrix();
           _app.translate((_app.width /2)-270, (_app.height / 2) + 50);
           _app.rotateZ(_app.frameCount / 100f);
           _app.image(_img, - _img.width /2, -_img.height / 2);
           _app.popMatrix();
       }
       else
       {
           _app.image(_img, 30, 250);
       }
   }
    
    /**
     * Cette permet de savoir si le
     * clique de la souris se situe
     * sur l'image du tourne disque.
     * @return boolean
     */
    private boolean IsInside()
    {
        return _app.mouseX > _x - _hw && _app.mouseX < _x + _hw && _app.mouseY > _y - _hh && _app.mouseY < _y + _hh;
    }
    
    public void Play()
    {
        _isPlayed = true;
    }
    
    public void Stop()
    {
        _isPlayed = false;
    }
    
    public void mousePressed()
    {
        System.out.println("------ press souris ------");
        if ( IsInside() )
        {
            System.out.println("Presse ok");
        }
    }
  
    public void mouseReleased()
    {
        if ( IsInside() )
        {
            System.out.println("Release ok");
        }
    }
}
